package cn.antho.pet.controller;

import cn.antho.pet.service.IPetOnsaleAuditLogService;
import cn.antho.pet.domain.PetOnsaleAuditLog;
import cn.antho.pet.query.PetOnsaleAuditLogQuery;
import cn.antho.basic.util.AjaxResult;
import cn.antho.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/petOnsaleAuditLog")
public class PetOnsaleAuditLogController {
    @Autowired
    public IPetOnsaleAuditLogService petOnsaleAuditLogService;


    /**
     * 保存和修改公用的
     * @param petOnsaleAuditLog  传递的实体
     * @return AjaxResult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody PetOnsaleAuditLog petOnsaleAuditLog){
        try {
            if( petOnsaleAuditLog.getId()!=null)
                petOnsaleAuditLogService.update(petOnsaleAuditLog);
            else
                petOnsaleAuditLogService.add(petOnsaleAuditLog);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            petOnsaleAuditLogService.delete(id);
            return AjaxResult.me().success();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public PetOnsaleAuditLog get(@PathVariable("id")Long id)
    {
        return petOnsaleAuditLogService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<PetOnsaleAuditLog> list(){

        return petOnsaleAuditLogService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<PetOnsaleAuditLog> json(@RequestBody PetOnsaleAuditLogQuery query)
    {
        return petOnsaleAuditLogService.queryByPage(query);
    }

    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids) {
        petOnsaleAuditLogService.batchDel(ids);
        return AjaxResult.me().success();
    }
}
